package services

import (
	"iris_product/datamodels"
	"iris_product/repositories"
)

type IOrderService interface {
	InsertOrder(orderInfo *datamodels.Order) (id int64,err error)
	DeleteOrder(id int64) bool
	UpdateOrderById(orderInfo *datamodels.Order) (err error)
	GetOrderInfoById(id int64) (orderInfo *datamodels.Order,err error)
	GetOrderAll()(orderList []*datamodels.Order,err error)
}

type OrderService struct {
	repo repositories.IOrder
}

func (o *OrderService) InsertOrder(orderInfo *datamodels.Order) (id int64, err error) {
	return o.repo.Insert(orderInfo)
}

func (o *OrderService) DeleteOrder(id int64) bool {
	return o.repo.Delete(id)
}

func (o *OrderService) UpdateOrderById(orderInfo *datamodels.Order) (err error) {
	return o.repo.Update(orderInfo)
}

func (o *OrderService) GetOrderInfoById(id int64) (orderInfo *datamodels.Order, err error) {
	return o.repo.SelectById(id)
}

func (o *OrderService) GetOrderAll() (orderList []*datamodels.Order, err error) {
	return o.repo.SelectAll()
}

func NewOrderService(repo repositories.IOrder) IOrderService {
	return &OrderService{
		repo:repo,
	}
}
